<@pp.dropOutputFile/>
<#include "../common/util.ftl">
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign app = doc.artifactid?replace(".", "/")>
<#assign package = table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name = "/" + package  + "/View/Setup" + fileName + "Form.vb"/>
<#assign package = table.moduleid?replace("/", ".")>
Imports System.Windows.Forms
Imports DevComponents.DotNetBar.SuperGrid
Imports DevComponents.DotNetBar
Imports Stone.common
Imports Stone.loading
Imports ${app}.${package}
Imports Stone

Public Class Setup${fileName}Form
    Private _${fileName}Service As I${fileName}Service = Nothing
    Private _Log As log4net.ILog = log4net.LogManager.GetLogger(Reflection.MethodBase.GetCurrentMethod().DeclaringType)
    Private _Obj As ${fileName} = Nothing
	
	Public Property DB As IDbConnection
	
    Private Sub Setup${fileName}Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
       _${fileName}Service = New ${fileName}ServiceSqliteImpl(_DB)
	   _Obj = _${fileName}Service.getOne(New Dictionary(Of String, Object)).Data
        If (Not IsNothing(_Obj)) Then
            Dim obj_string As ${fileName}String = New ${fileName}String(_Obj)
			<#list table.fields as field>
			<#if isText(field.type)>
			TextBoxX_${field.name?cap_first}.Text = obj_string.${field.name?cap_first}
			</#if>
			<#if isInteger(field.type)>
			IntegerInput_${field.name?cap_first}.Text = obj_string.${field.name?cap_first}
			</#if>
			<#if isReal(field.type)>
			DoubleInput_${field.name?cap_first}.Text = obj_string.${field.name?cap_first}
			</#if>
			<#if isDate(field.type)>
			DateTimeInput_${field.name?cap_first}.Text = obj_string.${field.name?cap_first}
			</#if>
			</#list>
        Else
            <#list table.fields as field>
			<#if isText(field.type)>
			TextBoxX_${field.name?cap_first}.Text = ""
			</#if>
			<#if isInteger(field.type)>
			IntegerInput_${field.name?cap_first}.Text = ""
			</#if>
			<#if isReal(field.type)>
			DoubleInput_${field.name?cap_first}.Text = ""
			</#if>
			<#if isDate(field.type)>
			DateTimeInput_${field.name?cap_first}.Text = ""
			</#if>
			</#list>
            ToastNotification.Show(Me, "加载参数失败！")
        End If
    End Sub

    Private Sub ButtonX_Save_Click(sender As System.Object, e As System.EventArgs) Handles ButtonX_Save.Click
        If (_Obj IsNot Nothing) Then
            <#list table.fields as field>
			<#if isText(field.type)>
			_Obj.${field.name?cap_first} = TextBoxX_${field.name?cap_first}.Text
			</#if>
			<#if isInteger(field.type)>
			_Obj.${field.name?cap_first} = IIf(IntegerInput_${field.name?cap_first}.IsEmpty, Nothing, IntegerInput_${field.name?cap_first}.Value)
			</#if>
			<#if isReal(field.type)>
			_Obj.${field.name?cap_first} = IIf(DoubleInput_${field.name?cap_first}.IsEmpty, Nothing, DoubleInput_${field.name?cap_first}.Value)
			</#if>
			<#if isDate(field.type)>
			_Obj.${field.name?cap_first} = IIf(DateTimeInput_${field.name?cap_first}.IsEmpty, Nothing, DateTimeInput_${field.name?cap_first}.Value)
			</#if>
			</#list>
            Dim oc As Outcome = _${fileName}Service.update(_Obj)
            If (oc.Success) Then
                ToastNotification.Show(Me, oc.Message)
            Else
                ToastNotification.Show(Me, oc.Message)
            End If
        End If
    End Sub
End Class
</#list>